package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Guanxing
 * @date 2021/9/19
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    //保存用户信息
    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    //修改用户信息
    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    //根据用户的id查询用户的信息
    @Override
    public UserInfo findById(Long userId) {
        return userInfoMapper.selectById(userId);
    }

    //查询用户
    @Override
    public PageBeanVo findUsersByPage(Integer pageNum, Integer pagesize) {
        IPage page = new Page(pageNum,pagesize);
        page = userInfoMapper.selectPage(page,null);
        return new PageBeanVo(pageNum,pagesize,page.getTotal(),page.getRecords());
    }

    //根据id删除用户
    @Override
    public void deleteById(String id) {
        userInfoMapper.deleteById(id);
    }
}
